package com.demo.money.controller.costdetails;

import com.demo.money.model.Costdetails;
import com.demo.money.service.CostdetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * CostdetailsEditByKeyHtml类<br>
 * costdetails/costdetailsEditByKey.html页面里的请求映射关系
 * <p>
 * <b>常用方法</b>：<br>
 * 1.updataCostdetails - 更新消费信息
 * <p>
 * <b>全类名</b>:com.demo.money.controller<br>
 * <b>类名</b>:CostdetailsEditByKeyHtml<br>
 * <b>创建者</b>:张峰浦<br>
 * <b>创建时间</b>:2020/3/17 19:38<br>
 */
@Controller
public class CostdetailsEditByKeyHtml {
    @Autowired
    private CostdetailsService costdetailsService;

    /**
     * 更新消费信息
     *
     * @param id                  主键（定位）
     * @param valid               有效？
     * @param userId              所属用户
     * @param timeTransaction     支出时间
     * @param amountOfMoney       应付金额
     * @param amountOfMoneyActual 实付金额
     * @param largeClass          分类
     * @param subClass            消费性质
     * @param tradename           消费名称
     * @param satisfactionDegree  满意度
     * @param note                备注
     * @return 响应页面地址
     */
    @RequestMapping({"updataCostdetails"})
    public String updataCostdetails(@RequestParam("id") Integer id, @RequestParam("valid") Integer valid, @RequestParam("userId") Integer userId, @RequestParam("timeTransaction") String timeTransaction, @RequestParam("amountOfMoney") Float amountOfMoney, @RequestParam("amountOfMoneyActual") Float amountOfMoneyActual, @RequestParam("largeClass") String largeClass, @RequestParam("subClass") String subClass, @RequestParam("tradename") String tradename, @RequestParam("satisfactionDegree") String satisfactionDegree, @RequestParam("note") String note) {


        costdetailsService.updateByPrimaryKey(new Costdetails(id, userId, valid, amountOfMoneyActual, amountOfMoney, largeClass, subClass, tradename, satisfactionDegree, note, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timeTransaction, new ParsePosition(0)), new Date()));

        return "costdetails/indexList";

    }
}
